//
//  FJDeleteAccountView.swift
//  FruitJuice
//
//  Created by Rui on 2023/12/17.
//

import UIKit
import SwiftEntryKit


class FJDeleteAccountView: UIView, SAAnimationDelegate, SAAnimationProtocol {
    
    func animationContainerViewSize() -> CGSize {
        CGSize(width: .screenWidth - 30.0, height: 335.0)
    }
    
    func animationContainerViewStyle() -> SAAnimationViewStyle {
        .center
    }
    
    func animationContainerScreenInteraction() -> EKAttributes.UserInteraction {
        .dismiss
    }
    
//    func animation(customAttributes attributes: EKAttributes) -> EKAttributes {
//        var attri = attributes
//        attri.positionConstraints.verticalOffset = .bottomSpace
//        return attri
//    }
    
    
    private lazy var titleLabel         = c_make_ex(UILabel.self)
        .alignment(.center).font(20.font_bold)
        .color(.black).text("Delete Account").end()
    
    private lazy var textView       = c_make_ex(UITextView.self)
        .bgColor("#EFEFEF").corner(22.5).placeholderFont(17.font_medium)
        .color("#000000").placeholderColor("#BEBEBE")
        .placeholder("You can tell us how to do better").end()
    
    lazy var cancelButton                 = c_make_ex(UIButton.self)
        .font(20.font_bold).color(.white).text("Cancel").bgColor("#FF9133")
        .addTarget(self, selector: #selector(museAction_cancel))
        .corner(25).end()
    
    lazy var submitButton                 = c_make_ex(UIButton.self)
        .font(20.font_bold).color("#FF9133").text("Delete Account").bgColor(.white)
        .addTarget(self, selector: #selector(museAction_submit))
        .corner(25).border("#FF9133", width: 2).end()
    
    private lazy var descLabel          = c_make_ex(UILabel.self)
        .line(0).alignment(.center).font(13.font_regular).color("#FF3131")
        .text("All your account information will be deleted\nplease consider carefully !").end()
    
    var didCleanCompletion: (() -> Void)?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.fj.bgColor("#FFFFFF").corner(28.0)
        subviews {
            titleLabel
            textView
            descLabel
            cancelButton
            submitButton
        }
        layout {
            24
            titleLabel
            10
            |-5-descLabel-5-|
            15
            |-12.5-textView-12.5-| ~ 140
            20
            |-15-submitButton| ~ 50
        }
        titleLabel.centerHorizontally()
        submitButton.width(185)
        cancelButton.width(115).height(50).trailing(12.5)
        cancelButton.CenterY == submitButton.CenterY
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    @objc private func museAction_cancel(_ sender: UIButton) {
//        muse.animation(dismiss: self)
        saAnimate.animation(dismiss: self)
    }
    
    @objc private func museAction_submit(_ sender: UIButton) {
        sender.isUserInteractionEnabled = false
        guard let content = textView.text, content.count > 0 else {
            "Please tell us why you want to leave us. ".toast_error
            return
        }
//        RT.deletUserWith { str in
//            AgoraRTMClient.shared._kit?.logout()
//            UserDefaults.standard.setValue(nil, forKey: "CollectList")
//            UserDefaults.standard.setValue(nil, forKey: "Following")
//            UserDefaults.standard.setValue(nil, forKey: "MessageList")
//            UserDefaults.standard.setValue(nil, forKey: "UserInfo")
//            UserDefaults.standard.setValue(nil, forKey: USERINFOKEY)
//            UserDefaults.standard.setValue(nil, forKey: "PayRooms")
//            UserDefaults.standard.removeObject(forKey: "boughtProductID")
//        }
//        textView.resignFirstResponder()
//        self.saAnimate.animation(dismiss: self){
//            // 登录界面
//            UIApplication.window?.rootViewController = LearningNavController(rootViewController: LearningWelcomeViewController())
//        }
    }
}
